package com.example.duomeitijuhe.ui.fragments;


import android.app.Activity;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.GestureDetector;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import com.example.duomeitijuhe.R;
import com.example.duomeitijuhe.adapter.InternetDataAdapter;
import com.example.duomeitijuhe.bean.GetInternetDataBean;
import com.example.duomeitijuhe.db.OperateDatabase;

import java.util.ArrayList;

/**
 * Created by Michael on 2014/10/14.
 */
public class DynamicFragment extends Fragment{

    private String[] data = {"a","b","c","d","e","f","g","h","j","k","L","m","n","o","p","q","r","s","t"};
    private ListView listView;
    int judge;
    private ArrayList<GetInternetDataBean> internetDataBeansList = new ArrayList<GetInternetDataBean>();

    View view;
    Activity activity;

    OperateDatabase operateDatabase;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View dynamicLayout = inflater.inflate(R.layout.dynamic, container, false);

        view = dynamicLayout;

        return dynamicLayout;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        activity = getActivity();
        initInternetData();
        InternetDataAdapter internetDataAdapter = new InternetDataAdapter(activity,R.layout.weibo_of_list_view,internetDataBeansList);
        listView = (ListView)activity.findViewById(R.id.dynamic_list_view);
        listView.setAdapter(internetDataAdapter);
        Log.i("dkfal","DynamicFragment");
    }
    public void initInternetData(){
        operateDatabase = new OperateDatabase(activity,1);
        Cursor cursor = operateDatabase.queryDb("InternetData");
        if (cursor.moveToFirst()){
            do {
                GetInternetDataBean getInternetDataBean = new GetInternetDataBean();
                String headUrl = cursor.getString(cursor.getColumnIndex("senderIconUrl"));
                getInternetDataBean.setSenderIconUrl(headUrl);

                String senderName = cursor.getString(cursor.getColumnIndex("senderName"));
                getInternetDataBean.setSenderName(senderName);

                String sendTime = cursor.getString(cursor.getColumnIndex("sendTime"));
                getInternetDataBean.setSendTime(sendTime);

                String content = cursor.getString(cursor.getColumnIndex("content"));
                getInternetDataBean.setContent(content);

                int i = cursor.getInt(cursor.getColumnIndex("isRetransmit"));
                getInternetDataBean.setIsRetransmit(i);
                if (i != 0) {
                    String originalSenderIcon = cursor.getString(cursor.getColumnIndex("originalSenderIconUrl"));
                    getInternetDataBean.setOriginalSenderIconUrl(originalSenderIcon);

                    String originalSenderName = cursor.getString(cursor.getColumnIndex("originalSenderName"));
                    getInternetDataBean.setOriginalSenderName(originalSenderName);

                    String originalContent = cursor.getString(cursor.getColumnIndex("originalContent"));
                    getInternetDataBean.setOriginalContent(originalContent);
                }
                internetDataBeansList.add(getInternetDataBean);
            }while (cursor.moveToNext());


        }

    }
}
